<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fn="http://www.w3.org/2005/02/xpath-functions">
    <xsl:param name="DOTNET2"/>
    
    
    	<xsl:template match="Class">
	
		<xsl:variable name="Name" select="Name"/>
		<xsl:variable name="TableName" select="DBName"/>
		<xsl:variable name="HeaderInfo" select="HeaderInfo/ProjectName"/>
		<xsl:variable name="IsComposite" select="IsComposite"/>
		
		
// GENNIT Castle ActiveRecord http://www.gennit.com
//
// Project: <xsl:value-of select="HeaderInfo/ProjectName"/>
//
// **************************************************************
// IMPORTANT BIT:
//
// This source code is is owned by you. No copyright is held by
// GENNIT. However, please note the disclaimer below
// **************************************************************
//
// GENNIT refers to the GENNIT website and anyone affiliated
// with the GENNIT system. Including but not limited to
// the administrator and service provider.
//
// Unless agreed to in writing, source code is distributed on an 
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
// either express or implied. GENNIT are not responsible for 
// your use/misuse of this code.

// When you use GENNIT code, you do so at your own risk and 
// GENNIT is not responsible for the accuracy, 
// reliability or functionality of the code. GENNIT expressly 
// disclaims any potential liability associated with use of 
// this generated code.



using System;

using Castle.ActiveRecord;
using NHibernate.Expression;
using Iesi.Collections;

namespace <xsl:value-of select="HeaderInfo/ProjectName"/>.Dal  
{


	<![CDATA[/// <summary> ]]>
	/// <xsl:value-of select="Name"/> is an ActiveRecord object associated with
	/// the <xsl:value-of select="DBName"/> table in the underlying database.
	///
	/// Note <xsl:value-of select="Name"/> is a partial class. The other part of
	/// the class resides in Methods/<xsl:value-of select="Name"/>.cs
	<![CDATA[/// </summary> ]]>
	[ Serializable ]
	<xsl:if test="IsNested='false'">
	<xsl:if test="IsComposite='false'">[ ActiveRecord ( "[<xsl:value-of select="DBName"/>]" ) ]</xsl:if>
	<xsl:if test="IsComposite='true'">[ CompositeKey ]</xsl:if>
	</xsl:if>
	public partial class <xsl:value-of select="Name"/><xsl:if test="IsNested='false'"> : <xsl:value-of select="HeaderInfo/ProjectName"/>.Dal.DataObject</xsl:if>
	{
	
		#region Primary Key
		
		<![CDATA[/// <summary> ]]>
		/// The primary key object for the <xsl:value-of select="Name"/> class.
		/// Stores its value in the DataObject base class ObjectID globally
		/// unique identifier.
		<![CDATA[/// </summary> ]]>
		[ PrimaryKey ( PrimaryKeyType.Guid ) ]
		public Guid <xsl:value-of select="Name"/>ID
		{
			get
			{
				return base.ObjectID;
			}
			
			set
			{
				base.ObjectID = value;
			}
		}
		
		#endregion
	
	
		#region Fields
		
		
		// single fields
		<xsl:for-each select="ClassAttribs/ClassAttributes[CType='single']">
		private <xsl:value-of select="Type"/><xsl:text> </xsl:text><xsl:value-of select="Name"/><xsl:if test="Type='DateTime'"> = DateTime.Now</xsl:if>;
		</xsl:for-each>
		
		// array fields
		<xsl:for-each select="ClassAttribs/ClassAttributes[CType='array']">
		[ System.Xml.Serialization.XmlArrayItem ( typeof ( <xsl:value-of select="Type"/> ) ) ]
		private ISet<xsl:text> </xsl:text><xsl:value-of select="Name"/> = new ListSet ();
		</xsl:for-each>

		#endregion
		
		
		#region Properties
		
		<xsl:for-each select="ClassAttribs/ClassAttributes[CType='single']">
		<![CDATA[/// <summary> ]]>
		/// <xsl:value-of select="PropertyName"/> is associated with the <xsl:value-of select="DBName"/> column in the 
		/// underlying database table <xsl:value-of select="$TableName"/>.
		<![CDATA[/// </summary> ]]>
		<xsl:if test="$IsComposite='false'">
		<xsl:if test="Key='true'">[ PrimaryKey ( PrimaryKeyType.Assigned , "<xsl:value-of select="DBName"/>" ) ]</xsl:if>
		<xsl:if test="Identity='true'">[ PrimaryKey ( PrimaryKeyType.Identity ) ]</xsl:if>
		<xsl:if test="Key='false' and Identity='false' and KnownClass='false' and IsNested='false'">[ Property ( "<xsl:value-of select="DBName"/>" ) ]</xsl:if>
		<xsl:if test="Key='false' and Identity='false' and KnownClass='true' and IsNested='false'">[ BelongsTo ( "<xsl:value-of select="DBName"/>" , Type=typeof ( <xsl:value-of select="Type"/> ) ) ]</xsl:if>
		</xsl:if>
		<xsl:if test="$IsComposite='true'">[ KeyProperty ( Column="<xsl:value-of select="DBName"/>" ) ]</xsl:if>
		<xsl:if test="IsNested='true'">[ Nested ]</xsl:if>
		public <xsl:value-of select="Type"/><xsl:text> </xsl:text><xsl:value-of select="PropertyName"/>
		{
			get
			{
				return this.<xsl:value-of select="Name"/>;
			}
			
			set
			{
				this.<xsl:value-of select="Name"/> = value;
			}
		}
		
		</xsl:for-each>
		
		
		<xsl:for-each select="ClassAttribs/ClassAttributes[CType='array']">
		<xsl:if test="HasMany='false'">
		<![CDATA[/// <summary> ]]>
		/// <xsl:value-of select="PropertyName"/> is array object which uses the database table <xsl:value-of select="$Name"/>_<xsl:value-of select="Name"/>
		/// to store primary keys (shown in ColumRef and ColumnKey attributes below).
		/// The lazy flag enables the collection to be loaded only once the property
		/// getter is accessed.
		<![CDATA[/// </summary> ]]>
		[ HasAndBelongsToMany ( typeof ( <xsl:value-of select="Type"/> ) ,
		   Table = "<xsl:if test="TableName=''"><xsl:value-of select="$Name"/>_<xsl:value-of select="Name"/></xsl:if><xsl:if test="TableName!=''"><xsl:value-of select="TableName"/></xsl:if>",
		   ColumnRef = "<xsl:if test="ColumnRef=''"><xsl:value-of select="$Name"/>ID</xsl:if><xsl:if test="ColumnRef!=''"><xsl:value-of select="ColumnRef"/></xsl:if>", ColumnKey="<xsl:if test="ColumnKey=''"><xsl:value-of select="Type"/>ID</xsl:if><xsl:if test="ColumnKey!=''"><xsl:value-of select="ColumnKey"/></xsl:if>" 
		   <xsl:if test="Where!=''">, Where="<xsl:value-of select="Where"/>"</xsl:if> , Lazy=true ) ]</xsl:if>
		   <xsl:if test="HasMany='true'">[ HasMany ( typeof ( <xsl:value-of select="Type"/> ) , Table="<xsl:value-of select="TableName"/>" , ColumnKey = "<xsl:value-of select="ColumnKey"/>" , Lazy=true ) ]</xsl:if>
		public ISet <xsl:value-of select="PropertyName"/>
		{
			get
			{
				return this.<xsl:value-of select="Name"/>;
			}
			
			set
			{
				this.<xsl:value-of select="Name"/> = value;
			}
		}
		
		</xsl:for-each>
		
		#endregion
	
	
	
	}


}
		
		
	</xsl:template>
    
</xsl:stylesheet>